package com.morningstar.flow.flowable.assigne;

import com.morningstar.flow.antvX6.common.Assign;
import com.morningstar.system.api.feign.ISystemUserFeign;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class AssigneeStrategySelectRole extends AssigneeStrategyHandler implements InitializingBean {
    @Resource
    ISystemUserFeign systemUserFeign;

    @Override
    public List<String> handler(Assign assign, ExecutionEntityImpl execution) {
        return systemUserFeign.selectUserByRoleIds(assign.getAssignValue()).stream().map(String::valueOf).toList();
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        register(AssigneeStrategy.STRATEGY_SELECT_ROLE, this);
    }
}
